package com.zjy.software.day13;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class TreeSet {
    public static void main(String[] args) {
        Map<String,String> map=new TreeMap<>();
        map.put("1","a");
        map.put("2","b");
        map.put("8","c");
        map.put("4","d");
        System.out.println("map = " + map);

        Map<Dog, Dog> dogMap=new TreeMap<>(new DogComparator());
        dogMap.put(new Dog("wangcai8"),new Dog("wangcai"));
        dogMap.put(new Dog("wangcai6"),new Dog("wangcai2"));
        dogMap.put(new Dog("wangcai2"),new Dog("wangcai2"));
        dogMap.put(new Dog("wangcai1"),new Dog("wangcai2"));
        System.out.println(dogMap);

        Map hashtable=new java.util.Hashtable();
        hashtable.put("1","a");
        //Hashtable的key和value都不能为null,否则报空指针异常
        hashtable.put("2",null);
//        hashtable.put(null,"b");

    }

}
class Dog{

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private  String name;

    public Dog(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}
class DogComparator implements Comparator<Dog> {

    @Override
    public int compare(Dog o1, Dog o2) {
        return o1.getName().compareTo(o2.getName());
    }
}